<?php

class StockPeer
{
  static public function getData($code)
  {
    $url  = 'http://hq.sinajs.cn/list='.$code;
    $content = file_get_contents($url);
    $content = substr($content, strpos($content, '"')+1, -3);
    if (empty($content)) {
      return false;
    }

    $array   = explode(',', $content);
    $array[0]= iconv('GB2312', 'UTF-8', $array[0]);
    $array[] = $array[3] - $array[2];
    $array[] = round($array[32]*100/$array[2], 2);
    $keys    = array('name','kaipan','shoupan', 'current', 'highest', 'lowest', 'buy_price', 'sell_price', 'turnover_count', 'turnover_value', 'buy1_count', 'buy1_price','buy2_count', 'buy2_price','buy3_count', 'buy3_price','buy4_count', 'buy4_price','buy5_count', 'buy5_price','sell1_count', 'sell1_price','sell2_count', 'sell2_price','sell3_count', 'sell3_price','sell4_count', 'sell4_price','sell5_count', 'sell5_price','date', 'time', 'increase', 'increase_percent');
    $data = array_combine($keys, $array);
    $data['code'] = $code;
    return $data;
  }
}
